home *** CD-ROM | disk | FTP | other *** search
/ io Programmo 37 / IOPROG_37.ISO / SOFT / Multilizer.exe / disk1 / data1.cab / data1 / [Group9]VCL Source Standard / ivmulreg.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1999-08-12  |  25.8 KB  |  1,147 lines

  1. {
  2.   This unit registers the dictionary and translator components of Multilizer.
  3.  
  4.   Copyrights 1995-1999 Innoview Data Technologies Oy
  5.  
  6.   If you use Delphi 2.0 (not Delphi 2.01) IvDSMult, IvPassWD and IvMLTP units
  7.   can not be used. In that case insert $ character before DEFINE word on
  8.   the next line.
  9. }
  10.  
  11. {DEFINE IVNOMDS}
  12.  
  13. unit IvMulReg;
  14.  
  15. {$I IVMULTI.INC}
  16.  
  17. interface
  18.  
  19. uses
  20.   Classes, DsgnIntf;
  21.  
  22. type
  23.   TIvFileNameProperty = class(TStringProperty)
  24.   protected
  25.     procedure BrowseFileName(const filter: String);
  26.  
  27.   public
  28.     function GetAttributes: TPropertyAttributes; override;
  29.   end;
  30.  
  31.   TIvMLDFileNameProperty = class(TIvFileNameProperty)
  32.   public
  33.     procedure Edit; override;
  34.   end;
  35.  
  36.   TIvDictionaryNameProperty = class(TStringProperty)
  37.   public
  38.     function GetAttributes: TPropertyAttributes; override;
  39.     procedure GetValues(Proc: TGetStrProc); override;
  40.   end;
  41.  
  42. procedure Register;
  43.  
  44. implementation
  45.  
  46. uses
  47. {$IFDEF WIN32}
  48.   Windows, Registry,
  49.   IvTargsD, IvLanguD, IvWReader, IvWParser, IvPassWD,
  50.   {$IFNDEF IVNOMDS}
  51.   IvDSMult, IvMLTP,
  52.   {$ENDIF}
  53. {$ELSE}
  54.   WinTypes, WinProcs,
  55.   IvTarD16,
  56. {$ENDIF}
  57.   Forms, Controls, Dialogs, SysUtils, TypInfo, DB, DBTables,
  58.   IvCommon, IvTargD, IvMulti, IvDbMult, IvFiMult, IvBinDic, IvLaSelD, IvSuSelD,
  59.   IvLoSelD, IvParser, IvReader, IvMlUtil, IvFiltEd, IvUsrDic, IvDictio,
  60.   IvAMulti, IvTestDi, IvAboutD, IvConMod, IvDlgMod;
  61.  
  62. {$IFDEF WIN32}
  63.   {$R IvMulR32.DCR}
  64. {$ELSE}
  65.   {$R IvMulR16.DCR}
  66. {$ENDIF}
  67.  
  68. { TIvTargetPropertiesProperty }
  69.  
  70. type
  71.   TIvTargetPropertiesProperty = class(TClassProperty)
  72.   public
  73.     function GetAttributes: TPropertyAttributes; override;
  74.     procedure Edit; override;
  75.   end;
  76.  
  77. function TIvTargetPropertiesProperty.GetAttributes: TPropertyAttributes;
  78. begin
  79.   Result := [paMultiSelect, paDialog{$IFDEF WIN32}, paRevertable{$ENDIF}];
  80. end;
  81.  
  82. procedure TIvTargetPropertiesProperty.Edit;
  83. var
  84.   translator: TIvTranslator;
  85.   targets: TIvTargetProperties;
  86.   dialog: TIvTargetPropertiesDialog;
  87. begin
  88.   translator := GetComponent(0) as TIvTranslator;
  89.   dialog := TIvTargetPropertiesDialog.Create(nil);
  90.   dialog.SetItems(TIvTargetProperties(GetOrdValue));
  91. {$IFDEF WIN32}
  92.   dialog.Translator := translator;
  93. {$ENDIF}
  94.  
  95.   try
  96.     if dialog.ShowModal = mrOk then
  97.     begin
  98.       targets := TIvTargetProperties.Create;
  99.       dialog.GetItems(targets);
  100.       SetOrdValue(LongInt(targets));
  101.       targets.Free;
  102.     end;
  103.   finally
  104.     dialog.Free;
  105.   end;
  106. end;
  107.  
  108.  
  109. { TIvDictionaryEditor }
  110.  
  111. type
  112.   TIvDictionaryEditor = class(TComponentEditor)
  113.   public
  114.     function GetVerbCount: Integer; override;
  115.     function GetVerb(index: Integer): String; override;
  116.  
  117.     procedure ExecuteVerb(index: Integer); override;
  118.     procedure Edit; override;
  119.   end;
  120.  
  121. function TIvDictionaryEditor.GetVerbCount: Integer;
  122. begin
  123.   Result := 1;
  124. end;
  125.  
  126. function TIvDictionaryEditor.GetVerb(index: Integer): String;
  127. begin
  128.   case index of
  129.     0: Result := 'About...';
  130.   end;
  131. end;
  132.  
  133. procedure TIvDictionaryEditor.ExecuteVerb(index: Integer);
  134. begin
  135.   case index of
  136.     0: Edit;
  137.   end;
  138. end;
  139.  
  140. procedure TIvDictionaryEditor.Edit;
  141. var
  142.   dialog: TIvAboutDialog;
  143. begin
  144.   dialog := TIvAboutDialog.Create(nil);
  145.   try
  146.     dialog.ShowModal;
  147.   finally
  148.     dialog.Free;
  149.   end;
  150. end;
  151.  
  152.  
  153. { TIvTranslatorEditor }
  154.  
  155. type
  156.   TIvTranslatorEditor = class(TComponentEditor)
  157.   public
  158.     function GetVerbCount: Integer; override;
  159.     function GetVerb(index: Integer): String; override;
  160.  
  161.     procedure ExecuteVerb(index: Integer); override;
  162.     procedure Edit; override;
  163.  
  164.     procedure About;
  165. {$IFDEF WIN32}
  166.     procedure DetectTargets;
  167. {$ENDIF}
  168.   end;
  169.  
  170. const
  171.   DEFAULT_TARGET_COUNT_C = 7;
  172.   DEFAULT_TARGETS_C: array[0..DEFAULT_TARGET_COUNT_C - 1] of String =
  173.   (
  174.     'Caption',
  175.     'Hint',
  176.     'Items',
  177.     'Lines',
  178.     'Hints',
  179.     'Tabs',
  180.     'Text'
  181.   );
  182.  
  183. function TIvTranslatorEditor.GetVerbCount: Integer;
  184. begin
  185. {$IFDEF WIN32}
  186.   Result := 3;
  187. {$ELSE}
  188.   Result := 2;
  189. {$ENDIF}
  190. end;
  191.  
  192. function TIvTranslatorEditor.GetVerb(index: Integer): String;
  193. begin
  194.   case index of
  195.     0: Result := 'About...';
  196.     1: Result := 'Targets...';
  197. {$IFDEF WIN32}
  198.     2: Result := 'Detect targets';
  199. {$ENDIF}
  200.   end;
  201. end;
  202.  
  203. procedure TIvTranslatorEditor.ExecuteVerb(index: Integer);
  204. begin
  205.   case index of
  206.     0: About;
  207.     1: Edit;
  208. {$IFDEF WIN32}
  209.     2: DetectTargets;
  210. {$ENDIF}
  211.   end;
  212. end;
  213.  
  214. {$IFDEF WIN32}
  215. procedure TIvTranslatorEditor.DetectTargets;
  216. begin
  217.   with Component as TIvTranslator do
  218.     DetectTargets(Targets, False);
  219. end;
  220. {$ENDIF}
  221.  
  222. procedure TIvTranslatorEditor.About;
  223. var
  224.   dialog: TIvAboutDialog;
  225. begin
  226.   dialog := TIvAboutDialog.Create(nil);
  227.   try
  228.     dialog.ShowModal;
  229.   finally
  230.     dialog.Free;
  231.   end;
  232. end;
  233.  
  234. procedure TIvTranslatorEditor.Edit;
  235. var
  236.   translator: TIvTranslator;
  237.   dialog: TIvTargetPropertiesDialog;
  238. begin
  239.   translator := Component as TIvTranslator;
  240.   dialog := TIvTargetPropertiesDialog.Create(nil);
  241.   dialog.SetItems(translator.Targets);
  242. {$IFDEF WIN32}
  243.   dialog.Translator := translator;
  244. {$ENDIF}
  245.  
  246.   try
  247.     if dialog.ShowModal = mrOk then
  248.     begin
  249.       translator.Targets.SetDefault;
  250.       dialog.GetItems(translator.Targets);
  251.       Designer.Modified;
  252.     end;
  253.   finally
  254.     dialog.Free;
  255.   end;
  256. end;
  257.  
  258. { TIvDictionaryNameProperty }
  259.  
  260. function TIvDictionaryNameProperty.GetAttributes: TPropertyAttributes;
  261. begin
  262.   Result := [paMultiSelect, paValueList, paSortList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  263. end;
  264.  
  265. procedure TIvDictionaryNameProperty.GetValues(Proc: TGetStrProc);
  266. var
  267.   i: Integer;
  268. begin
  269.   for i := 0 to Dictionaries.Count - 1 do
  270.     if Dictionaries[i].DictionaryName <> '' then
  271.       Proc(Dictionaries[i].DictionaryName);
  272. end;
  273.  
  274. { TIvPrimaryLanguageProperty }
  275.  
  276. type
  277.   TIvPrimaryLanguageProperty = class(TIntegerProperty)
  278.   public
  279.     procedure SetValue(const value: String); override;
  280.     procedure GetValues(Proc: TGetStrProc); override;
  281.     function GetAttributes: TPropertyAttributes; override;
  282.   end;
  283.  
  284. procedure TIvPrimaryLanguageProperty.SetValue(const value: String);
  285. var
  286.   i, primary: Integer;
  287.   tempValue, str: String;
  288.   dictionary: TIvDictionary;
  289.   parser: TIvStringParser;
  290. begin
  291.   dictionary := GetComponent(0) as TIvDictionary;
  292.  
  293.   { If locale has been bound to language the changing of the property is not
  294.     possible. }
  295.  
  296.   if dictionary.Binding = ivbiLocaleToLanguage then
  297.     dictionary.Binding := ivbiLanguageToLocale;
  298. {
  299.     raise EPropertyError.Create(
  300.       'The PrimaryLanguage property has been bound to the Language property!'#13#10 +
  301.       'Change it or set the Binding property to ivbiLanguageToLocale');
  302. }
  303.  
  304.   { Gets the primary id }
  305.  
  306.   parser := TIvStringParser.CreateValue(value, ' ');
  307.   try
  308.     tempValue := parser.GetString;
  309.   finally
  310.     parser.Free;
  311.   end;
  312.  
  313.   { Checks the value and sets the property }
  314.  
  315.   primary := -1;
  316.   try
  317.     dictionary.Open;
  318.     if tempValue = '0' then
  319.       primary := LANG_NEUTRAL
  320.     else
  321.     begin
  322.       for i := 0 to dictionary.LanguageCount - 1 do
  323.       begin
  324.         str := IntToStr(dictionary.Languages[i].Primary);
  325.         if tempValue = str then
  326.         begin
  327.           primary := dictionary.Languages[i].Primary;
  328.           Break;
  329.         end;
  330.       end;
  331.     end;
  332.  
  333.     { Updates the primary and the sub ids of the dictionary }
  334.  
  335.     if primary >= 0 then
  336.     begin
  337.       { Sets the primary and sub languages }
  338.  
  339.       SetOrdValue(primary);
  340.       dictionary.SubLanguage := SUBLANG_NEUTRAL;
  341.  
  342.       { If the language has been bound to locale, sets the language }
  343.  
  344.       if dictionary.Binding = ivbiLanguageToLocale then
  345.         dictionary.Language := dictionary.LocaleToLanguage(dictionary.Locale);
  346.     end
  347.     else
  348.       raise EPropertyError.Create('''' + value + ''' is not supported by the dictionary');
  349.   finally
  350.     dictionary.Close;
  351.   end;
  352. end;
  353.  
  354. procedure TIvPrimaryLanguageProperty.GetValues(Proc: TGetStrProc);
  355. var
  356.   i, j: Integer;
  357.   str: String;
  358.   found: Boolean;
  359.   languages: TStringList;
  360.   dictionary: TIvDictionary;
  361.   language: TIvLanguage;
  362. begin
  363.   dictionary := GetComponent(0) as TIvDictionary;
  364.  
  365.   languages := TStringList.Create;
  366.   try
  367.     try
  368.       dictionary.Open;
  369.       for i := dictionary.DefaultLanguage to dictionary.LanguageCount - 1 do
  370.       begin
  371.         language := dictionary.Languages[i];
  372.  
  373.         found := False;
  374.         for j := 0 to languages.Count - 1 do
  375.         begin
  376.           if Integer(languages.Objects[j]) = language.Primary then
  377.           begin
  378.             found := True;
  379.             Break;
  380.           end;
  381.         end;
  382.  
  383.         if not found then
  384.         begin
  385.           str := dictionary.ComposeLocaleName(
  386.             language.EnglishName,
  387.             '',
  388.             language.Primary,
  389.             SUBLANG_NEUTRAL,
  390.             language.CodePage,
  391.             False,
  392.             nil);
  393.           if str = '' then
  394.             str := dictionary.Languages[i].EnglishName;
  395.           languages.AddObject(IntToStr(language.Primary) + ' - ' + str, TObject(language.Primary));
  396.          end;
  397.       end;
  398.     finally
  399.       dictionary.Close;
  400.     end;
  401.  
  402.     Proc('0 - Default');
  403.     for i := 0 to languages.Count - 1 do
  404.       Proc(languages[i]);
  405.   finally
  406.     languages.Free;
  407.   end;
  408. end;
  409.  
  410. function TIvPrimaryLanguageProperty.GetAttributes: TPropertyAttributes;
  411. begin
  412.   Result := [paValueList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  413. end;
  414.  
  415.  
  416. { TIvSubLanguageProperty }
  417.  
  418. type
  419.   TIvSubLanguageProperty = class(TIntegerProperty)
  420.   public
  421.     procedure SetValue(const value: String); override;
  422.     procedure GetValues(Proc: TGetStrProc); override;
  423.     function GetAttributes: TPropertyAttributes; override;
  424.   end;
  425.  
  426. procedure TIvSubLanguageProperty.SetValue(const value: String);
  427. var
  428.   sub: Integer;
  429.   parser: TIvStringParser;
  430.   dictionary: TIvDictionary;
  431. begin
  432.   dictionary := GetComponent(0) as TIvDictionary;
  433.  
  434.   { If locale has been bound to language the changing of the property is not
  435.     possible. }
  436.  
  437.   if dictionary.Binding = ivbiLocaleToLanguage then
  438.     dictionary.Binding := ivbiLanguageToLocale;
  439. {
  440.     raise EPropertyError.Create(
  441.       'The PrimaryLanguage property has been bound to the Language property!'#13#10 +
  442.       'Change it or set the Binding property to ivbiLanguageToLocale');
  443. }
  444.  
  445.   { Checks the value }
  446.  
  447.   parser := TIvStringParser.CreateValue(value, ' ');
  448.   try
  449.     try
  450.       sub := parser.GetInteger;
  451.     except
  452.       raise EPropertyError.Create('''' + value + ''' is not an integer');
  453.     end;
  454.  
  455.     if (sub < 0) or (sub > $3F) then
  456.       raise EPropertyError.Create('''' + value + ''' is not a valid sub language value');
  457.  
  458.     SetOrdValue(sub);
  459.  
  460.     { If the language has been bound to locale, sets the language }
  461.  
  462.     if dictionary.Binding = ivbiLanguageToLocale then
  463.     begin
  464.       try
  465.         dictionary.Open;
  466.         dictionary.Language := dictionary.LocaleToLanguage(dictionary.Locale);
  467.       finally
  468.         dictionary.Close;
  469.       end;
  470.     end;
  471.   finally
  472.     parser.Free;
  473.   end;
  474. end;
  475.  
  476. procedure TIvSubLanguageProperty.GetValues(Proc: TGetStrProc);
  477. var
  478.   i: Integer;
  479.   locales: TList;
  480.   locale: TIvLocale;
  481.   dictionary: TIvDictionary;
  482. begin
  483.   dictionary := GetComponent(0) as TIvDictionary;
  484.   if dictionary.PrimaryLanguage = LANG_NEUTRAL then
  485.   begin
  486.     { Primary language is neutral }
  487.  
  488.     Proc('0 - Neutral');
  489.     Proc('1 - User default');
  490.     Proc('2 - System default');
  491.   end
  492.   else
  493.   begin
  494.     { Primary language is a specific langauge }
  495.  
  496.     locales := TList.Create;
  497.     dictionary.Open;
  498.     try
  499.       Proc('0 - Neutral');
  500.       dictionary.GetLocales(locales);
  501.       for i := 0 to locales.Count - 1 do
  502.       begin
  503.         locale := TIvLocale(locales[i]);
  504.         if locale.Primary = dictionary.PrimaryLanguage then
  505.           Proc(IntToStr(locale.Sub) + ' - ' + locale.EnglishCountryName);
  506.       end;
  507.     finally
  508.       dictionary.Close;
  509.       dictionary.FreeList(locales);
  510.     end;
  511.   end;
  512. end;
  513.  
  514. function TIvSubLanguageProperty.GetAttributes: TPropertyAttributes;
  515. begin
  516.   Result := [paValueList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  517. end;
  518.  
  519.  
  520. { TIvLanguageProperty }
  521.  
  522. type
  523.   TIvLanguageProperty = class(TIntegerProperty)
  524.   public
  525.     procedure SetValue(const value: String); override;
  526.     procedure GetValues(Proc: TGetStrProc); override;
  527.     function GetAttributes: TPropertyAttributes; override;
  528.   end;
  529.  
  530. procedure TIvLanguageProperty.SetValue(const value: String);
  531. var
  532.   language: Integer;
  533.   parser: TIvStringParser;
  534.   dictionary: TIvDictionary;
  535. begin
  536.   dictionary := GetComponent(0) as TIvDictionary;
  537.  
  538.   { If language has been bound to locale the changing of the property is not
  539.     possible. }
  540.  
  541.   if dictionary.Binding = ivbiLanguageToLocale then
  542.     dictionary.Binding := ivbiLocaleToLanguage;
  543. {
  544.     raise EPropertyError.Create(
  545.       'The Language property has been bound to the PrimaryLanguage and the SubLanguage properties!'#13#10 +
  546.       'Change them or set the Binding property to ivbiLocaleToLanguage');
  547. }
  548.  
  549.   { Sets the language }
  550.  
  551.   parser := TIvStringParser.CreateValue(value, ' ');
  552.   try
  553.     language := StrToIntDef(parser.GetString, -1);
  554.     SetOrdValue(language);
  555.   finally
  556.     parser.Free;
  557.   end;
  558.  
  559.   { If locale has been bound to language, sets it. }
  560.  
  561.   if dictionary.Binding = ivbiLocaleToLanguage then
  562.   begin
  563.     case language of
  564.       -2:
  565.       begin
  566.         dictionary.PrimaryLanguage := 0;
  567.         dictionary.SubLanguage := SUBLANG_SYS_DEFAULT;
  568.       end;
  569.  
  570.       -1:
  571.       begin
  572.         dictionary.PrimaryLanguage := 0;
  573.         dictionary.SubLanguage := SUBLANG_DEFAULT;
  574.       end;
  575.     else
  576.       try
  577.         dictionary.Open;
  578.         dictionary.Locale := dictionary.Languages[language].Locale;
  579.       finally
  580.         dictionary.Close;
  581.       end;
  582.     end;
  583.   end;
  584. end;
  585.  
  586. procedure TIvLanguageProperty.GetValues(Proc: TGetStrProc);
  587. var
  588.   i: Integer;
  589.   languages: TList;
  590.   dictionary: TIvDictionary;
  591. begin
  592.   languages := TList.Create;
  593.   try
  594.     dictionary := GetComponent(0) as TIvDictionary;
  595.     try
  596.       dictionary.Open;
  597.       dictionary.GetLanguageDatas(languages);
  598.     finally
  599.       dictionary.Close;
  600.     end;
  601.  
  602.     Proc('-2 - System default');
  603.     Proc('-1 - User default');
  604.     for i := 0 to languages.Count - 1 do
  605.       with TIvLanguage(languages[i]) do
  606.       begin
  607.         if Primary = LANG_NEUTRAL then
  608.           Proc('0 - Native')
  609.         else
  610.           Proc(IntToStr(i) + ' - ' + EnglishName);
  611.       end;
  612.   finally
  613.     TIvDictionary.FreeList(languages);
  614.   end;
  615. end;
  616.  
  617. function TIvLanguageProperty.GetAttributes: TPropertyAttributes;
  618. begin
  619.   Result := [paValueList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  620. end;
  621.  
  622.  
  623. { TIvFileNameProperty }
  624.  
  625. function TIvFileNameProperty.GetAttributes: TPropertyAttributes;
  626. begin
  627.   Result := [paMultiSelect, paDialog
  628. {$IFDEF WIN32}
  629.     , paRevertable
  630. {$ENDIF}
  631.     ];
  632. end;
  633.  
  634. procedure TIvFileNameProperty.BrowseFileName(const filter: String);
  635. var
  636.   dlg: TOpenDialog;
  637. begin
  638.   dlg := TOpenDialog.Create(nil);
  639.   dlg.Filename := GetValue;
  640.   dlg.Filter := filter;
  641.   dlg.HelpContext := 0;
  642.   dlg.Options := dlg.Options + [ofShowHelp, ofPathMustExist, ofFileMustExist];
  643.  
  644.   try
  645.     if dlg.Execute then
  646.       SetValue(dlg.Filename);
  647.   finally
  648.     dlg.Free;
  649.   end;
  650. end;
  651.  
  652.  
  653. { TIvMLDFileNameProperty }
  654.  
  655. procedure TIvMLDFileNameProperty.Edit;
  656. begin
  657.   BrowseFileName('Multilizer dictionary files (*.mld)|*.mld|All files (*.*)|*.*|');
  658. end;
  659.  
  660.  
  661. { TIvTextFileNameProperty }
  662.  
  663. type
  664.   TIvTextFileNameProperty = class(TIvFileNameProperty)
  665.   public
  666.     procedure Edit; override;
  667.   end;
  668.  
  669. procedure TIvTextFileNameProperty.Edit;
  670. begin
  671.   BrowseFileName('Text files (*.txt)|*.txt|All files (*.*)|*.*|');
  672. end;
  673.  
  674.  
  675. { TIvDatabaseNameProperty }
  676.  
  677. type
  678.   TIvDatabaseNameProperty = class(TStringProperty)
  679.   public
  680.     function GetAttributes: TPropertyAttributes; override;
  681.     procedure GetValues(Proc: TGetStrProc); override;
  682.   end;
  683.  
  684. function TIvDatabaseNameProperty.GetAttributes: TPropertyAttributes;
  685. begin
  686.   Result := [paMultiSelect, paValueList, paSortList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  687. end;
  688.  
  689. procedure TIvDatabaseNameProperty.GetValues(Proc: TGetStrProc);
  690. var
  691.   list: TStringList;
  692.   i: Integer;
  693. begin
  694.   list := TStringList.Create;
  695.   Session.GetDatabaseNames(list);
  696.  
  697.   for i := 0 to list.Count - 1 do
  698.     Proc(list[i]);
  699.  
  700.   list.Free;
  701. end;
  702.  
  703.  
  704. { TIvTableNameProperty }
  705.  
  706. type
  707.   TIvTableNameProperty = class(TStringProperty)
  708.   public
  709.     function GetAttributes: TPropertyAttributes; override;
  710.     procedure GetValues(Proc: TGetStrProc); override;
  711.   end;
  712.  
  713. function TIvTableNameProperty.GetAttributes: TPropertyAttributes;
  714. begin
  715.   Result := [paMultiSelect, paValueList, paSortList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  716. end;
  717.  
  718. procedure TIvTableNameProperty.GetValues(Proc: TGetStrProc);
  719. var
  720.   i: Integer;
  721.   list: TStringList;
  722. begin
  723.   list := TStringList.Create;
  724.   Session.GetTableNames(
  725.     (GetComponent(0) as TIvDBDictionary).DatabaseName,
  726.     '',
  727.     True,
  728.     False,
  729.     list);
  730.   for i := 0 to list.Count - 1 do
  731.     Proc(list[i]);
  732.   list.Free;
  733. end;
  734.  
  735. { TIvTableTypeProperty }
  736.  
  737. type
  738.   TIvTableTypeProperty = class(TEnumProperty)
  739.   public
  740.     procedure GetValues(Proc: TGetStrProc); override;
  741.   end;
  742.  
  743. procedure TIvTableTypeProperty.GetValues(Proc: TGetStrProc);
  744. var
  745.   I: Integer;
  746.   EnumType: PTypeInfo;
  747. begin
  748.   EnumType := GetPropType;
  749.   with GetTypeData(EnumType)^ do
  750.     for I := MinValue to MaxValue - 1 do
  751. {$IFDEF WIN32}
  752.       Proc(GetEnumName(EnumType, I));
  753. {$ELSE}
  754.       Proc(GetEnumName(EnumType, I)^);
  755. {$ENDIF}
  756. end;
  757.  
  758. { TIvTestPrimaryProperty }
  759.  
  760. type
  761.   TIvTestPrimaryProperty = class(TIntegerProperty)
  762.   public
  763.     procedure SetValue(const value: String); override;
  764.     procedure GetValues(Proc: TGetStrProc); override;
  765.     function GetAttributes: TPropertyAttributes; override;
  766.   end;
  767.  
  768. procedure TIvTestPrimaryProperty.SetValue(const value: String);
  769. var
  770.   parser: TIvStringParser;
  771. begin
  772.   parser := TIvStringParser.CreateValue(value, ' ');
  773.   try
  774.     SetOrdValue(StrToIntDef(parser.GetString, 0));
  775.   finally
  776.     parser.Free;
  777.   end;
  778. end;
  779.  
  780. procedure TIvTestPrimaryProperty.GetValues(Proc: TGetStrProc);
  781. const
  782.   PRIMARIES_C: array[1..64] of String =
  783.   (
  784.     'Arabic',
  785.     'Bulgarian',
  786.     'Catalan',
  787.     'Chinese',
  788.     'Czech',
  789.     'Danish',
  790.     'German',
  791.     'Greek',
  792.     'English',
  793.     'Spanish',
  794.     'Finnish',
  795.     'French',
  796.     'Hebrew',
  797.     'Hungarian',
  798.     'Icelandic',
  799.     'Italian',
  800.     'Japanese',
  801.     'Korean',
  802.     'Dutch',
  803.     'Norwegian',
  804.     'Polish',
  805.     'Portuguese',
  806.     'Rhaeto-Romanic',
  807.     'Romanian',
  808.     'Russian',
  809.     'Croatian/Serbian',
  810.     'Slovak',
  811.     'Albanian',
  812.     'Swedish',
  813.     'Thai',
  814.     'Turkish',
  815.     'Urdu',
  816.     'Indonesian',
  817.     'Ukrainian',
  818.     'Belarusian',
  819.     'Slovenian',
  820.     'Estonian',
  821.     'Latvian',
  822.     'Lithuanian',
  823.     '',
  824.     'Farsi',
  825.     'Vietnamese',
  826.     '',
  827.     '',
  828.     'Basque',
  829.     'Sorbian',
  830.     'Macedonian',
  831.     'Sutu',
  832.     'Tsonga',
  833.     'Tswana',
  834.     'Venda',
  835.     'Xhosa',
  836.     'Zulu',
  837.     'Afrikaans',
  838.     '',
  839.     'Faeroese',
  840.     'Hindi',
  841.     'Maltese',
  842.     'Sami',
  843.     'Scots Gaelic',
  844.     '',
  845.     '',
  846.     '',
  847.     ''
  848.   );
  849. var
  850.   i: Integer;
  851.   value, str: String;
  852.   languages: TStringList;
  853. begin
  854.   languages := TStringList.Create;
  855.   try
  856.     for i := 1 to 64 do
  857.     begin
  858.       value := IntToStr(i);
  859. {$IFDEF WIN32}
  860.       str := GetLocaleStr(IvMakeLangId(i, SUBLANG_NEUTRAL), LOCALE_SENGLANGUAGE, '');
  861. {$ELSE}
  862.       str := '';
  863. {$ENDIF}
  864.       if str = '' then
  865.         str := PRIMARIES_C[i];
  866.       if str <> '' then
  867.         value := value + ' - ' + TIvDictionary.ComposeLanguageName(str, i, 0, False, nil);
  868.       languages.Add(value);
  869.     end;
  870.  
  871.     Proc('0 - Default');
  872.     for i := 0 to languages.Count - 1 do
  873.       Proc(languages[i]);
  874.   finally
  875.     languages.Free;
  876.   end;
  877. end;
  878.  
  879. function TIvTestPrimaryProperty.GetAttributes: TPropertyAttributes;
  880. begin
  881.   Result := [paValueList{$IFDEF WIN32}, paRevertable{$ENDIF}];
  882. end;
  883.  
  884. {$IFDEF WIN32}
  885. { TIvCheckLevelProperty }
  886.  
  887. type
  888.   TIvCheckLevelProperty = class(TEnumProperty)
  889.   public
  890.     function GetAttributes: TPropertyAttributes; override;
  891.   end;
  892.  
  893. function TIvCheckLevelProperty.GetAttributes: TPropertyAttributes;
  894. begin
  895.   Result := [paValueList, paMultiSelect, paRevertable];
  896. end;
  897.  
  898.  
  899. {$IFNDEF IVNOMDS}
  900. type
  901.   TIvMDSDictionaryNameProperty = class(TStringProperty)
  902.   public
  903.     function GetAttributes: TPropertyAttributes; override;
  904.     procedure GetValues(Proc: TGetStrProc); override;
  905.   end;
  906.  
  907. var
  908.   LastMDSAddress, LastMDSUserName, LastMDSPassword: String;
  909.  
  910. function TIvMDSDictionaryNameProperty.GetAttributes: TPropertyAttributes;
  911. begin
  912.   Result := [paMultiSelect, paValueList, paSortList, paRevertable];
  913. end;
  914.  
  915. procedure TIvMDSDictionaryNameProperty.GetValues(Proc: TGetStrProc);
  916. var
  917.   i: Integer;
  918.   list: TStringList;
  919.   dictionary: TIvServerDictionary;
  920.   dialog: TIvPasswordDialog;
  921. begin
  922.   // Creates a temporaly dictionary that gets the available dictionary names.
  923.  
  924.   dictionary := TIvServerDictionary.Create(nil);
  925.  
  926.   if dictionary.Address = '' then
  927.   begin
  928.     MessageDlg(
  929.       'You have not specified the Address property.',
  930.       mtInformation,
  931.       [mbOK],
  932.       0);
  933.     Exit;
  934.   end;
  935.  
  936.   try
  937.     with GetComponent(0) as TIvServerDictionary do
  938.     begin
  939.       dictionary.Address := Address;
  940.       dictionary.Port := Port;
  941.     end;
  942.  
  943.     while True do
  944.     begin
  945.       // Asks the user id
  946.  
  947.       if LastMDSAddress = dictionary.Address then
  948.       begin
  949.         // The user has previously logged in to this server
  950.  
  951.         dictionary.UserName := LastMDSUserName;
  952.         dictionary.Password := LastMDSPassword;
  953.       end
  954.       else
  955.       begin
  956.         dialog := TIvPasswordDialog.Create(nil);
  957.         try
  958.           dialog.SavePassword.Visible := False;
  959.           if dialog.ShowModal = mrOK then
  960.           begin
  961.             dictionary.UserName := dialog.UserName.Text;
  962.             dictionary.Password := dialog.Password.Text;
  963.           end
  964.           else
  965.             Exit;
  966.         finally
  967.           dialog.Free;
  968.         end;
  969.       end;
  970.  
  971.       // Makes a connection to MDS and gets the dictionary name
  972.  
  973.       try
  974.         LastMDSAddress := '';
  975.         LastMDSUserName := '';
  976.         LastMDSPassword := '';
  977.         try
  978.           dictionary.Login;
  979.         except
  980.           on e: Exception do
  981.           begin
  982.             MessageDlg(
  983.               'Could not log in to the Dictionary Server: ' + e.Message,
  984.               mtError,
  985.               [mbOK],
  986.               0);
  987.             Exit;
  988.           end;
  989.         end;
  990.  
  991.         list := TStringList.Create;
  992.         dictionary.GetDictionaries(list, nil, nil);
  993.         for i := 0 to list.Count - 1 do
  994.           Proc(list[i]);
  995.         list.Free;
  996.  
  997.         LastMDSAddress := dictionary.Address;
  998.         LastMDSUserName := dictionary.UserName;
  999.         LastMDSPassword := dictionary.Password;
  1000.  
  1001.         Break;
  1002.       finally
  1003.         dictionary.Logout;
  1004.       end;
  1005.     end;
  1006.   finally
  1007.     dictionary.Free;
  1008.   end;
  1009. end;
  1010. {$ENDIF}
  1011. {$ENDIF}
  1012.  
  1013. procedure Register;
  1014. begin
  1015.   { Dictionary components }
  1016.  
  1017.   RegisterComponents(ML_SHEET_C, [TIvBinaryDictionary]);
  1018.   RegisterComponents(ML_SHEET_C, [TIvTextDictionary]);
  1019. {$IFDEF WIN32}
  1020.   {$IFNDEF IVNOMDS}
  1021.   RegisterComponents(ML_SHEET_C, [TIvServerDictionary]);
  1022.   {$ENDIF}
  1023. {$ENDIF}
  1024.   RegisterComponents(ML_SHEET_C, [TIvDBDictionary]);
  1025.   RegisterComponents(ML_SHEET_C, [TIvUserDictionary]);
  1026.   RegisterComponents(ML_SHEET_C, [TIvTestDictionary]);
  1027.  
  1028.   { Translator component }
  1029.  
  1030.   RegisterComponents(ML_SHEET_C, [TIvTranslator]);
  1031.  
  1032.   { Module components }
  1033.  
  1034.   RegisterComponents(ML_SHEET_C, [TIvControlModule]);
  1035.   RegisterComponents(ML_SHEET_C, [TIvDialogModule]);
  1036.  
  1037.   RegisterPropertyEditor(
  1038.     TypeInfo(Integer),
  1039.     TIvDictionary,
  1040.     'PrimaryLanguage',
  1041.     TIvPrimaryLanguageProperty);
  1042.  
  1043.   RegisterPropertyEditor(
  1044.     TypeInfo(Integer),
  1045.     TIvDictionary,
  1046.     'SubLanguage',
  1047.     TIvSubLanguageProperty);
  1048.  
  1049.   RegisterPropertyEditor(
  1050.     TypeInfo(Integer),
  1051.     TIvDictionary,
  1052.     'Language',
  1053.     TIvLanguageProperty);
  1054.  
  1055.   RegisterPropertyEditor(
  1056.     TypeInfo(String),
  1057.     TIvBinaryDictionary,
  1058.     'FileName',
  1059.     TIvMLDFileNameProperty);
  1060.  
  1061.   RegisterPropertyEditor(
  1062.     TypeInfo(String),
  1063.     TIvTextDictionary,
  1064.     'FileName',
  1065.     TIvTextFileNameProperty);
  1066.  
  1067.   RegisterPropertyEditor(
  1068.     TypeInfo(String),
  1069.     TIvTextDictionary,
  1070.     'LanguageFileName',
  1071.     TIvTextFileNameProperty);
  1072.  
  1073.   RegisterPropertyEditor(
  1074.     TypeInfo(String),
  1075.     TIvTextDictionary,
  1076.     'LocaleFileName',
  1077.     TIvTextFileNameProperty);
  1078.  
  1079.   RegisterPropertyEditor(
  1080.     TypeInfo(String),
  1081.     TIvDBDictionary,
  1082.     'DatabaseName',
  1083.     TIvDatabaseNameProperty);
  1084.  
  1085.   RegisterPropertyEditor(
  1086.     TypeInfo(String),
  1087.     TIvDBDictionary,
  1088.     'TableType',
  1089.     TIvTableTypeProperty);
  1090.  
  1091.   RegisterPropertyEditor(
  1092.     TypeInfo(String),
  1093.     TIvDBDictionary,
  1094.     'TableName',
  1095.     TIvTableNameProperty);
  1096.  
  1097.   RegisterPropertyEditor(
  1098.     TypeInfo(String),
  1099.     TIvDBDictionary,
  1100.     'LanguageTableName',
  1101.     TIvTableNameProperty);
  1102.  
  1103.   RegisterPropertyEditor(
  1104.     TypeInfo(String),
  1105.     TIvDBDictionary,
  1106.     'LocaleTableName',
  1107.     TIvTableNameProperty);
  1108.  
  1109.   RegisterPropertyEditor(
  1110.     TypeInfo(String),
  1111.     TIvCustomTranslator,
  1112.     'DictionaryName',
  1113.     TIvDictionaryNameProperty);
  1114.  
  1115.   RegisterPropertyEditor(
  1116.     TypeInfo(TIvTargetProperties),
  1117.     TIvTranslator,
  1118.     'Targets',
  1119.     TIvTargetPropertiesProperty);
  1120.  
  1121.   RegisterPropertyEditor(
  1122.     TypeInfo(Integer),
  1123.     TIvTestDictionary,
  1124.     'TestPrimary',
  1125.     TIvTestPrimaryProperty);
  1126.  
  1127. {$IFDEF WIN32}
  1128.   RegisterPropertyEditor(
  1129.     TypeInfo(String),
  1130.     TIvServerDictionary,
  1131.     'RemoteDictionaryName',
  1132.     TIvMDSDictionaryNameProperty);
  1133.  
  1134.   RegisterPropertyEditor(
  1135.     TypeInfo(TIvCheckLevel),
  1136.     TIvDictionary,
  1137.     'CheckLevel',
  1138.     TIvCheckLevelProperty);
  1139. {$ENDIF}
  1140.  
  1141.   RegisterComponentEditor(TIvTranslator, TIvTranslatorEditor);
  1142.   RegisterComponentEditor(TIvDictionary, TIvDictionaryEditor);
  1143. end;
  1144.  
  1145. end.
  1146.  
  1147.